dotmp(TString fin)
{
  TFile::Open(fin);
  TTree * tree= (TTree*)gDirectory->Get("newdraw_Tree");
  gStyle->SetOptStat("emroun");
  
  tree->SetAlias("dl0","sqrt(1+dydx0^2+dzdx0^2)");
  tree->SetAlias("dl1","sqrt(1+dydx1^2+dzdx1^2)");
  tree->SetAlias("dl","(dl0+dl1)/2.");
  
  tree->SetAlias("norq", "trdQ0/AliTRDdEdxBaseUtils::Q0MeanTRDpp(pow(10, ltbg))");
  
  TString cut="trdnch0==6 && ltbg>0.75 && ltbg < 0.85 && dl<1.1";
  
  new TCanvas;
  //gPad->SetGrid()
  
  //TH2D *hh=new TH2D("hh","",36, TMath::Pi()/2*TMath::RadToDeg()/20., TMath::Pi()*5/2*TMath::RadToDeg()/20.,100,0,3); tree->Draw("norq:AliTRDdEdxBaseUtils::GetRedefinedPhi(phi)*TMath::RadToDeg()/20.>>hh",cut,"colz");
  
  //TH2D *hh=new TH2D("hh","", 100, -0.9, 0.9,100,0,3); tree->Draw("norq:eta>>hh",cut,"colz");
  //TH2D *hh=new TH2D("hh","", 100, -0.9, 0.9,100,1,3); tree->Draw("dl:eta>>hh",cut,"colz");
  //TH2D *hh=new TH2D("hh","", 100, -0.9, 0.9,60,0,180); tree->Draw("trdncls0:eta>>hh",cut,"colz");
  
  //TH2D *hh=new TH2D("hh","",100,1,1.8,100,0,3); tree->Draw("norq:dl>>hh",cut,"colz");
  
  //TH2D *hh=new TH2D("hh","",100,1,1.8,60,0,180); tree->Draw("trdncls0:dl>>hh",cut,"colz");
  
  //TH2D *hh=new TH2D("hh","",100, -0.5, 4, 50,80,180); tree->Draw("trdncls0:ltbg>>hh",cut,"colz");

  //TH2D *hh=new TH2D("hh","",100, 0, 4.5, 60,1,1.8); tree->Draw("dl:ltbg>>hh",cut,"colz");
  //TH2D *hh=new TH2D("hh","",100, 0, 4.5, 60, 0, 0.03); tree->Draw("trdQ0/trdncls0:ltbg>>hh",cut,"colz");
  //TH2D *hh=new TH2D("hh","",100, 0, 3, 60, 0, 180); tree->Draw("trdncls0:trdQ0>>hh",cut,"colz");
  
  TH2D *hh=new TH2D("hh","",60,0,180,100,0,3); tree->Draw("norq:trdncls0>>hh",cut,"colz");
  
  //TH2D *hh=new TH2D("hh","",180,0,180,100,0,3); tree->Draw("norq:trdncls0/dl>>hh",cut,"colz");
  
  gStyle->SetOptStat(0);
  cc=new TCanvas;
  gPad->SetGrid();
  TH2D *h2= XGLUtils::NormalHist(hh, 50, 1);
  TH1D *hnor=0, *hmpv=0, *hwid=0, *hres=0, *hchi=0;
  XGLUtils::FitSlicesY(h2, 0x0, hnor, hmpv, hwid, hres, hchi, 50, 0, 0.99);
  //h2->SetXTitle("#eta")
  //h2->SetYTitle("N");
  //h2->SetXTitle("#phi")
  //h2->SetYTitle("Q/<Q>");
  //h2->GetYaxis()->SetRangeUser(0.5, 1.5);
  h2->Draw("colz");
  gPad->SetLogz();
  hmpv->SetLineWidth(2);
  hmpv->SetMarkerSize(2);
  hmpv->Draw("same e");
  
  /*
  new TCanvas;
  gPad->SetGrid();

  h2->FitSlicesY();
  newwid = (TH1D*)gDirectory->Get("hhnor_2");
  newwid->GetXaxis()->SetRangeUser(10, 158);
  newwid->SetMinimum(0);
  newwid->SetMaximum(0.45);
  newwid->SetTitle("");
  newwid->SetYTitle("Resolution of <Q>_{0.55}");
  newwid->Draw();

  //newwid->GetXaxis()->SetRangeUser(80,150);
  Double_t par[10]={1}, err[10], chi[2];
  Int_t flag = XGLUtils::ChisquareFit(newwid, XGLUtils::InvSqrt, 1, par, err, chi);
  TH1D * hfit=new TH1D("hfit","", 800, 0, 200);
  for(Int_t ii=1; ii<=hfit->GetNbinsX(); ii++){
    const Double_t xx = hfit->GetBinCenter(ii);
    const Double_t yy = XGLUtils::InvSqrt(&xx, par);
    hfit->SetBinContent(ii,yy);
  }
  hfit->SetLineColor(kRed);
  hfit->Draw("same C");
  */

  TFile* fout=new TFile("qvsn_allnch.root","recreate");
  hh->Write();
  h2->Write();
  hnor->Write();
  hmpv->Write();
  hwid->Write();
  hres->Write();
  //hhnor_2->Write();
  //hfit->Write();
  fout->Save();
  fout->Close();
  //  hres->Draw();
  //hnor->Draw();
}
